package com.um.jdy.platform.platform.manager;

import cn.hutool.core.bean.BeanUtil;
import com.um.jdy.common.base.enums.YesOrNo;
import com.um.jdy.common.platform.code.PlatformCode;
import com.um.jdy.common.platform.entity.dto.WithdrawSettingDTO;
import com.um.jdy.common.platform.entity.po.WithdrawSetting;
import com.um.jdy.common.platform.service.WithdrawSettingService;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.manager.BaseManager;
import org.springframework.stereotype.Component;

/**
 * 管理类：提现设置
 */
@Component
public class WithdrawSettingManager extends BaseManager<WithdrawSettingService> {

    /**
     * 详情
     *
     * @return
     */
    public Response<WithdrawSetting> get() {
        WithdrawSetting withdrawSetting = service.getEntity("com_id", getComId());
        if(withdrawSetting == null){
            withdrawSetting = new WithdrawSetting();
            withdrawSetting.setComId(getComId());
            withdrawSetting.setStatus(YesOrNo.Yes.name());
            withdrawSetting.setBank(YesOrNo.Yes.name());
            withdrawSetting.setWechat(YesOrNo.Yes.name());
            withdrawSetting.setHandFee(0.6f);
            withdrawSetting.setDayMax(200000);
            withdrawSetting.setSingleMax(50000);
            service.save(withdrawSetting);
        }
        return Response.success(withdrawSetting);
    }

    /**
     * 更新
     *
     * @param id
     * @param appSettingDTO
     * @return
     */
    public Response update(String id, WithdrawSettingDTO appSettingDTO) {
        if(appSettingDTO.getSingleMax() > appSettingDTO.getDayMax()){
            return Response.failed(PlatformCode.SingleMaxExceedDayMaximum);
        }

        WithdrawSetting withdrawSetting = BeanUtil.copyProperties(appSettingDTO, WithdrawSetting.class);
        withdrawSetting.setPlatformWithdrawSettingId(id);
        service.updateEntity(withdrawSetting);
        return Response.success();
    }
}
